#include <my_head.h>

typedef struct _Color{
    unsigned char b;
    unsigned char g;
    unsigned char r;
    unsigned char a; // 透明度  0 全透明  255 不透明
}color_t;

int main(int argc, const char *argv[]){
    // 打开文件
    FILE *fp = fopen("ddm.bmp", "r+");
    if(NULL == fp)
        ERR_LOG("fopen error");
    // 类型
    char bftype[3] = {0};
    fread(bftype, 1, 2, fp);
    printf("bftype = [%s]\n", bftype); // BM
    // 大小
    int bfsize = 0;
    fread(&bfsize, 1, 4, fp);
    printf("bfsize = [%d]\n", bfsize); // 5679130
    // 偏移量
    int offset = 0;
    fseek(fp, 10, SEEK_SET);
    fread(&offset, 1, 4, fp);
    printf("offset = [%d]\n", offset); // 138
    // 宽度
    int width = 0;
    fseek(fp, 4, SEEK_CUR);
    fread(&width, 1, 4, fp);
    printf("width = [%d]\n", width); // 1574
    // 高度
    int height = 0;
    fread(&height, 1, 4, fp);
    printf("height = [%d]\n", height); // -902
    // 位深度
    int bitcount = 0;
    fseek(fp, 2, SEEK_CUR);
    fread(&bitcount, 1, 2, fp);
    printf("bitcount = [%d]\n", bitcount); // 32

    // 将光标定位到第一个像素点位置
    fseek(fp, offset, SEEK_SET);
    //将光标定位到鼻子左上角
    fseek(fp,(590+325*width)*bitcount/8,SEEK_CUR);
    color_t color = {155, 155, 155, 255};
    int i = 0;
    int j = 0;
    for(i = 0; i <420-325 ; i++){
        for(j = 0; j < 700-590; j++){
           fwrite(&color,1,4,fp);
        }
        fseek(fp,(width-(700-590))*bitcount/8,SEEK_CUR);
    }
    
    // 关闭文件
    fclose(fp);
    return 0;
}